#include "event_driver.h"
#include "async_server.h"
#include "globals.h"
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/bind.hpp>

using namespace std;
using namespace boost;
using namespace async_server;

const int16_t SERVER_PORT = 8899;

int ping_handle(auroral::event::EventDriver &eventDriver, string eventType, shared_ptr<void> data);
int pong_handle(auroral::event::EventDriver &eventDriver, string eventType, shared_ptr<void> data);
int undef_msg_handle(auroral::event::EventDriver &eventDriver, string eventType, shared_ptr<void> data);
int do_ping_handle(auroral::event::EventDriver &eventDriver, string eventType, shared_ptr<void> data);
int do_pong_handle(auroral::event::EventDriver &eventDriver, string eventType, shared_ptr<void> data);

auroral::event::EventDriver eventDriver;

int main(int argc, char *argv[])
{
	eventDriver.registerEvent("ping");
	eventDriver.registerEvent("pong");
	eventDriver.registerEvent("do_ping");
	eventDriver.registerEvent("do_pong");
	eventDriver.registerEvent("undef");

	eventDriver.addHandle("ping", ping_handle);
	eventDriver.addHandle("pong", pong_handle);
	eventDriver.addHandle("do_ping", do_ping_handle);
	eventDriver.addHandle("do_pong", do_pong_handle);
	eventDriver.addHandle("undef", undef_msg_handle);

	boost::asio::io_service io_service;
	AsyncSession::pointer pAsyncSession = AsyncSession::pointer(new AsyncSession(io_service));
	auroral::net::TcpServer tcpServer(io_service, pAsyncSession, SERVER_PORT);
	boost::thread thread1(boost::bind(&boost::asio::io_service::run, &io_service));
	return eventDriver.exec();
}